import { getDictionaryApi, getComboItemsListApi, getComboItemsList2Api } from '@/api/Device-all/Device-view'

// 字典查询
const getDictionary = async (name) => {
  const res = await getDictionaryApi(name)
  return res.data.list
}

// 目标组件/查询视图下拉框组件下拉框选项列表
const getComboItemsList = async (id) => {
  const res = await getComboItemsListApi(id)
  return res.data.list
}

// 目标组件/查询视图下拉框组件下拉框选项列表
const getComboItemsList2 = async (id) => {
  const res = await getComboItemsList2Api(id)
  return res.data.list
}

// 字典名称显示转换事件
const ConvertCodeAction = [
  {
    componentName: 'NtInput',
    span: 24,
    label: '字典分类',
    prop: 'codeType',
    rules: [
      {
        required: true,
        message: '请输入字典分类',
        trigger: 'blur'
      }
    ]
  }
]

// 数据库查询显示转换事件
const ConvertSqlAction = [
  {
    componentName: 'NtInput',
    span: 24,
    textAreaConfig: 'textarea',
    rows: 4,
    label: '查询语句',
    prop: 'querySql',
    rules: [
      {
        required: true,
        message: '请输入查询语句',
        trigger: 'blur'
      }
    ]
  },
  {
    componentName: 'NtSelect',
    span: 24,
    label: '查询数据源',
    prop: 'dataSource',
    selectList: () => getDictionary('VomComboDataSource'),
    def: true
  }
]

// 字典数据下拉框级联事件
const SelectFilterCodeAction = [
  {
    componentName: 'NtSelect',
    span: 24,
    label: '事件动作',
    prop: 'actionEvent',
    selectList: () => getDictionary('VomEventType'),
    def: true,
    rules: [
      {
        required: true,
        message: '选择事件动作',
        trigger: 'change'
      }
    ]
  },
  {
    componentName: 'NtSelect',
    span: 24,
    label: '目标组件',
    prop: 'targetComponent',
    selectList: (_commonData) => getComboItemsList(_commonData.id),
    def: true,
    rules: [
      {
        required: true,
        message: '请选择目标组件',
        trigger: 'change'
      }
    ]
  },
  {
    componentName: 'NtSelect',
    span: 24,
    label: '取值组件',
    prop: 'valueComponent',
    selectList: (_commonData) => getComboItemsList2(_commonData.id),
    def: true,
    rules: [
      {
        required: true,
        message: '请选择取值组件',
        trigger: 'blur'
      }
    ]
  },
  {
    componentName: 'NtInput',
    span: 24,
    label: '字典分类',
    prop: 'codeType',
    rules: [
      {
        required: true,
        message: '请输入字典分类',
        trigger: 'blur'
      }
    ]
  },
  {
    componentName: 'NtSwitch',
    span: 12,
    label: '自动设值',
    prop: 'autoSetValue',
    rules: [
      {
        required: true,
        message: '请选择是否自动设值',
        trigger: 'change'
      }
    ]
  }
]

// 数据库查询下拉框级联事件
const SelectFilterSqlAction = [
  {
    componentName: 'NtSelect',
    span: 24,
    label: '事件动作',
    prop: 'actionEvent',
    selectList: () => getDictionary('VomEventType'),
    def: true,
    rules: [
      {
        required: true,
        message: '选择事件动作',
        trigger: 'change'
      }
    ]
  },
  {
    componentName: 'NtSelect',
    span: 24,
    label: '目标组件',
    prop: 'targetComponent',
    selectList: (_commonData) => getComboItemsList(_commonData.id),
    def: true,
    rules: [
      {
        required: true,
        message: '请选择目标组件',
        trigger: 'change'
      }
    ]
  },
  {
    componentName: 'NtSelect',
    span: 24,
    label: '取值组件',
    prop: 'valueComponent',
    selectList: (_commonData) => getComboItemsList2(_commonData.id),
    def: true,
    rules: [
      {
        required: true,
        message: '请选择取值组件',
        trigger: 'blur'
      }
    ]
  },
  {
    componentName: 'NtInput',
    span: 24,
    textAreaConfig: 'textarea',
    rows: 4,
    label: '查询语句',
    prop: 'querySql',
    rules: [
      {
        required: true,
        message: '请输入查询语句',
        trigger: 'blur'
      }
    ]
  },
  {
    componentName: 'NtSelect',
    span: 24,
    label: '查询数据源',
    prop: 'dataSource',
    selectList: () => getDictionary('VomComboDataSource'),
    def: true
  },
  {
    componentName: 'NtSwitch',
    span: 12,
    label: '自动设值',
    prop: 'autoSetValue',
    rules: [
      {
        required: true,
        message: '请选择是否自动设值',
        trigger: 'change'
      }
    ]
  }
]

// 自定义下拉框取值事件
const CustomAction = [
  {
    componentName: 'NtSelect',
    span: 24,
    label: '事件动作',
    prop: 'actionEvent',
    selectList: () => getDictionary('VomEventType'),
    def: true,
    rules: [
      {
        required: true,
        message: '选择事件动作',
        trigger: 'change'
      }
    ]
  },
  {
    componentName: 'NtSelect',
    span: 24,
    label: '自定义事件',
    prop: 'customCode',
    selectList: () => getDictionary('VomCustomAction'),
    def: true,
    rules: [
      {
        required: true,
        message: '选择自定义事件',
        trigger: 'change'
      }
    ]
  }
]

// 字典名称设值事件
const SetCodeNameAction = [
  {
    componentName: 'NtSelect',
    span: 24,
    label: '事件动作',
    prop: 'actionEvent',
    selectList: () => getDictionary('VomEventType'),
    def: true,
    rules: [
      {
        required: true,
        message: '选择事件动作',
        trigger: 'change'
      }
    ]
  },
  {
    componentName: 'NtSelect',
    span: 24,
    label: '目标组件',
    prop: 'targetComponent',
    selectList: (_commonData) => getComboItemsList(_commonData.id),
    def: true,
    rules: [
      {
        required: true,
        message: '请选择目标组件',
        trigger: 'change'
      }
    ]
  },
  {
    componentName: 'NtInput',
    span: 24,
    label: '字典分类',
    prop: 'codeType',
    rules: [
      {
        required: true,
        message: '请输入字典分类',
        trigger: 'blur'
      }
    ]
  }
]

// 数据库查询设值事件
const SetSqlValueAction = [
  {
    componentName: 'NtSelect',
    span: 24,
    label: '事件动作',
    prop: 'actionEvent',
    selectList: () => getDictionary('VomEventType'),
    def: true,
    rules: [
      {
        required: true,
        message: '选择事件动作',
        trigger: 'change'
      }
    ]
  },
  {
    componentName: 'NtSelect',
    span: 24,
    label: '目标组件',
    prop: 'targetComponent',
    selectList: (_commonData) => getComboItemsList(_commonData.id),
    def: true,
    rules: [
      {
        required: true,
        message: '请选择目标组件',
        trigger: 'change'
      }
    ]
  },
  {
    componentName: 'NtInput',
    span: 24,
    textAreaConfig: 'textarea',
    rows: 4,
    label: '查询语句',
    prop: 'querySql',
    rules: [
      {
        required: true,
        message: '请输入查询语句',
        trigger: 'blur'
      }
    ]
  },
  {
    componentName: 'NtSelect',
    span: 24,
    label: '查询数据源',
    prop: 'dataSource',
    selectList: () => getDictionary('VomComboDataSource'),
    def: true,
    rules: [
      {
        required: true,
        message: '请选择查询数据源',
        trigger: 'change'
      }
    ]
  }
]

// 表达式设值事件
const SetELValueAction = [
  {
    componentName: 'NtSelect',
    span: 24,
    label: '事件动作',
    prop: 'actionEvent',
    selectList: () => getDictionary('VomEventType'),
    def: true,
    rules: [
      {
        required: true,
        message: '选择事件动作',
        trigger: 'change'
      }
    ]
  },
  {
    componentName: 'NtSelect',
    span: 24,
    label: '目标组件',
    prop: 'targetComponent',
    selectList: (_commonData) => getComboItemsList(_commonData.id),
    def: true,
    rules: [
      {
        required: true,
        message: '请选择目标组件',
        trigger: 'change'
      }
    ]
  },
  {
    componentName: 'NtInput',
    span: 24,
    label: '表达式',
    prop: 'elScript',
    rules: [
      {
        required: true,
        message: '请输入表达式',
        trigger: 'blur'
      }
    ]
  }
]

// 组件禁用设置事件
const SetDisableAction = [
  {
    componentName: 'NtSelect',
    span: 24,
    label: '事件动作',
    prop: 'actionEvent',
    selectList: () => getDictionary('VomEventType'),
    def: true,
    rules: [
      {
        required: true,
        message: '选择事件动作',
        trigger: 'change'
      }
    ]
  },
  {
    componentName: 'NtSelect',
    span: 24,
    label: '目标组件',
    prop: 'targetComponent',
    selectList: (_commonData) => getComboItemsList(_commonData.id),
    def: true,
    rules: [
      {
        required: true,
        message: '请选择目标组件',
        trigger: 'change'
      }
    ]
  },
  {
    componentName: 'NtSwitch',
    span: 12,
    label: '是否重置',
    prop: 'reset',
    rules: [
      {
        required: true,
        message: '请选择是否重置',
        trigger: 'change'
      }
    ]
  }
]

// 组件只读设置事件
const SetReadOnlyAction = [
  {
    componentName: 'NtSelect',
    span: 24,
    label: '事件动作',
    prop: 'actionEvent',
    selectList: () => getDictionary('VomEventType'),
    def: true,
    rules: [
      {
        required: true,
        message: '选择事件动作',
        trigger: 'change'
      }
    ]
  },
  {
    componentName: 'NtSelect',
    span: 24,
    label: '目标组件',
    prop: 'targetComponent',
    selectList: (_commonData) => getComboItemsList(_commonData.id),
    def: true,
    rules: [
      {
        required: true,
        message: '请选择目标组件',
        trigger: 'change'
      }
    ]
  },
  {
    componentName: 'NtSwitch',
    span: 12,
    label: '是否重置',
    prop: 'reset',
    rules: [
      {
        required: true,
        message: '请选择是否重置',
        trigger: 'change'
      }
    ]
  }
]

export {
  ConvertCodeAction,
  ConvertSqlAction,
  SelectFilterCodeAction,
  SelectFilterSqlAction,
  CustomAction,
  SetCodeNameAction,
  SetSqlValueAction,
  SetELValueAction,
  SetDisableAction,
  SetReadOnlyAction
}
